<!doctype html>
<html>
  <head>
    <title>Socket.IO chat</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style>
      * { margin: 0; padding: 0; box-sizing: border-box; }
      body { font: 13px Helvetica, Arial; }
      form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
      form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
      form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
      #messages { list-style-type: none; margin: 0; padding: 0; }
      #messages li { padding: 5px 10px; }
      #messages li:nth-child(odd) { background: #eee; }
    </style>
  </head>
  <body>
    <ul id="messages"></ul>
    <button id="analytic"> Tạo thống kê </button>
	<button id="connecttwo"> Kết nối muộn </button>

    <script src="public/js/socket.io-1.2.0.js"></script>
<script src="http://babybean.vn/vi/public/babybean/ver2/js/jquery-1.3.2.min.js"></script>
    <script>
      var socketUrl = '';
      var socket = [];
      var room = "test02";
      
	  for(i = 1; i<= 1;i++)
	  {
			test(i);
	  }
	  
	  function test(i)
	  {
		//$.getJSON( "http://125.212.192.115/get-balance/index.php", function( data ) {
			socketUrl = '192.168.12.220:9000';//data;
			//console.log(data);
			socket[i] = io(socketUrl, {'force new connection': true });
			socketInit(socket[i]);
		  //});
	  }
	  
      function socketInit(s, _id){
          s.on('connect', function(){
				s.emit('jointvshow',27, 'nhatnv');
				$("#analytic").click(function()
				{
					s.emit('creatAnalytics', 27, 2, 2, 1, 1606, null, null);
				});
				$("#connecttwo").click(function()
				{
					s.emit('connecttwo', 30);
				});
				
				s.on('addOneVote', function(data, id_tvshow, id_channel, _id_question, isshare, isshowannalytic_, _show_id)
				{
					console.log(data, id_tvshow, id_channel, _id_question, isshare, isshowannalytic_, _show_id);
				});
				
				s.on('responConnecttwo', function(question, id_tvshow, id_question, is_share, is_show_analytic, show_id, stop_vote)
				{
					console.log(question, id_tvshow, id_question, is_share, is_show_analytic, show_id, stop_vote);
				});
				s.on('CountJoin', function(number, id_tvshow)
				{
					console.log('number, id_tvshow', number, id_tvshow);
				});
				s.on('receiveAnalytic', function(vote, id_tvshow, tanalyticsRoom, troom, user_id, id_question)
				{
					console.log(vote, id_tvshow, tanalyticsRoom, troom, user_id, id_question);
				});
				
				s.on('stop_vote_client', function(id_tvshow, show_id, id_question)
				{
					console.log(id_tvshow, show_id, id_question);
				});
          });

      }
    </script>
  </body>
</html>
